package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分类相关接口")
@RestController
@Slf4j
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 分类分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分类分页查询")
    public Result<PageResult> Page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类分页查询，参数为："+categoryPageQueryDTO);
        PageResult pageResult = categoryService.PageQuery(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @ApiOperation("修改分类")
    @PutMapping(consumes = "application/json")
    public Result UpdateCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("修改分类:{}",categoryDTO);
        categoryService.UpdateCategory(categoryDTO);
        return Result.success();
    }

    /**
     * 启用和禁用分类
     * @param status
     * @param id
     * @return
     */
    @ApiOperation("禁用和启用分类")
    @PostMapping("status/{status}")
    public  Result StartOrStop(@PathVariable Integer status,Long id){
        log.info("启用或禁用的菜品分类id和状态：{},{}",id,status);
       categoryService.StartOrStop(status,id);
        return Result.success();
    }

    /**
     * 新增菜品分类
     * @param categoryDTO
     * @return
     */
    @PostMapping()
    @ApiOperation("新增菜品分类")
    public Result Save( @RequestBody CategoryDTO categoryDTO){
        categoryService.Save(categoryDTO);
        return Result.success();
    }

    /**\
     *前端参数传递错误
     * @param id
     * @return
     */

    @ApiOperation("根据id进行删除")
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable Long id){
        categoryService.DeletaById(id);
        return Result.success();
    }

    /**
     * 前端没有传入正确类型参数
     * @param type
     * @return
     */

    @ApiOperation("根据分类类型进行查询")
    @GetMapping("/list")
    public Result<List<Category>> getList(Integer type){
        List<Category> categoryList = categoryService.getList(type);
        return Result.success(categoryList);
    }


}
